package com.aletto.general_store.data;

import android.content.SharedPreferences;

import com.aletto.general_store.data.model.Address;
import com.aletto.general_store.data.model.AuctionGoods;
import com.aletto.general_store.data.model.AuctionPageGoods;
import com.aletto.general_store.data.model.ConsumerOrder;
import com.aletto.general_store.data.model.Goods;
import com.aletto.general_store.data.model.GoodsDetails;
import com.aletto.general_store.data.model.OrderCompany;
import com.aletto.general_store.data.model.OrderCreate;
import com.aletto.general_store.data.model.OrderDetails;
import com.aletto.general_store.data.model.OrderNumber;
import com.aletto.general_store.data.model.OrderScore;
import com.aletto.general_store.data.model.PageResponse;
import com.aletto.general_store.data.model.Response;
import com.aletto.general_store.data.model.SearchKeyword;
import com.aletto.general_store.data.model.ServiceOrder;
import com.aletto.general_store.data.model.Store;
import com.aletto.general_store.data.model.StoreFavorites;
import com.aletto.general_store.data.model.StoreOrder;
import com.aletto.general_store.data.model.Upload;
import com.aletto.general_store.data.model.UserDetails;
import com.sisyphus.spinach.core.model.IPageResponse;
import com.sisyphus.spinach.core.model.IResponse;

import java.io.File;
import java.util.List;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.functions.Function;

public class DataRepository implements IDataSource {

    private static IDataSource sDataRepository;

    public static IDataSource getInstance() {
        if (sDataRepository == null) {
            synchronized (DataRepository.class) {

                if (sDataRepository == null) {
                    sDataRepository = new DataRepository();
                }
            }
        }

        return sDataRepository;
    }

    private       SharedPreferences mPreferences;
    private final IDataSource       mRemoteDataSource;

    private DataRepository() {
//        mRemoteDataSource = new MockDataSource();
        mRemoteDataSource = new RemoteDataSource();
        //mLocalCacheDataSource = new LocalCacheDataSource();

        // 本地存储
        //mPreferences = MetaEraApplication.sInstance
        //        .getSharedPreferences("data_local_cache", Context.MODE_PRIVATE);

        // getAppConfig().subscribeOn(Schedulers.io()).subscribe(); // app信息
    }


    @Override
    public Observable<Response<Upload>> upload(File file) {
        return mRemoteDataSource.upload(file);
    }

    @Override
    public Observable<Response<Store>> getShopDetails(String id, int status) {
        return mRemoteDataSource.getShopDetails(id, status);
    }

    @Override
    public Observable<Response<PageResponse<Goods>>> getGoodsByShopId(
            int page, int size, String shopId, int type, int orderType) {

        return mRemoteDataSource.getGoodsByShopId(page, size, shopId, type, orderType);
    }

    @Override
    public Observable<Response<PageResponse<Goods>>> homeGoods(int page, int size) {
        return mRemoteDataSource.homeGoods(page, size);
    }

    @Override
    public Observable<Response<GoodsDetails>> getGoodsDetails(String id, int status) {
        return mRemoteDataSource.getGoodsDetails(id, status);
    }

    @Override
    public Observable<Response<UserDetails>> login(String address) {
        return mRemoteDataSource.login(address);
    }

    @Override
    public Observable<Response<UserDetails>> userDetails() {
        return mRemoteDataSource.userDetails();
    }

    @Override
    public Observable<Response<Object>> updateUserDetails(String id, String name, String head_img, String sign) {
        return mRemoteDataSource.updateUserDetails(id, name, head_img, sign);
    }


    @Override
    public Observable<Response<List<String>>> hotSearch() {


       return mRemoteDataSource.hotSearch();

    }

    @Override
    public Observable<Response<PageResponse<Goods>>> searchGoods(int page, int size, String keyword) {
        return mRemoteDataSource.searchGoods(page, size, keyword);
    }

    @Override
    public Observable<Response<PageResponse<Store>>> storeLists(int page, int size, String keyword) {
        return mRemoteDataSource.storeLists(page, size, keyword);
    }

    @Override
    public Observable<Response<List<String>>> searchPrompt(int type, String keyword) {
        return mRemoteDataSource.searchPrompt(type, keyword);
    }

    @Override
    public Observable<Response<List<Address>>> addressList() {

        return mRemoteDataSource.addressList();
    }

    @Override
    public Observable<Response<Object>> addAddress(String name, String phone, String address) {
        return mRemoteDataSource.addAddress(name, phone, address);
    }

    @Override
    public Observable<Response<Object>> deleteAddress(int id) {
        return mRemoteDataSource.deleteAddress(id);
    }

    @Override
    public Observable<Response<Object>> defaultAddress(int id) {
        return mRemoteDataSource.defaultAddress(id);
    }

    @Override
    public Observable<Response<PageResponse<Goods>>> history(int page, int size) {
        return mRemoteDataSource.history(page, size);
    }

    @Override
    public Observable<Response<Object>> clearHistory(String id) {
        return mRemoteDataSource.clearHistory(id);
    }

    @Override
    public Observable<Response<OrderNumber>> myOrderInfo() {
        return mRemoteDataSource.myOrderInfo();
    }

    @Override
    public Observable<Response<PageResponse<ConsumerOrder>>> myOrderList(int page, int size, int type, String keyword) {
        return mRemoteDataSource.myOrderList(page, size, type, keyword);
    }

    @Override
    public Observable<Response<PageResponse<StoreOrder>>> shopOrderList(int page, int size, int type, String keyword) {
        return mRemoteDataSource.shopOrderList(page, size, type, keyword);
    }

    @Override
    public Observable<Response<AuctionPageGoods>> myGoodsList(int page, int size, Integer status, String keyword) {
        return mRemoteDataSource.myGoodsList(page, size, status, keyword);
    }

    @Override
    public Observable<Response<Object>> favoritesGoods(String id, boolean isFavorites) {
        return mRemoteDataSource.favoritesGoods(id, isFavorites);
    }

    @Override
    public Observable<Response<PageResponse<Goods>>> favoritesGoodsList(int page, int size) {
        return mRemoteDataSource.favoritesGoodsList(page, size);
    }

    @Override
    public Observable<Response<Object>> favoritesStore(String id, boolean isFavorites) {
        return mRemoteDataSource.favoritesStore(id, isFavorites);
    }

    @Override
    public Observable<Response<PageResponse<StoreFavorites>>> favoritesStoreList(int page, int size) {
        return mRemoteDataSource.favoritesStoreList(page, size);
    }

    @Override
    public Observable<Response<Object>> clearFavorites(int type) {
        return mRemoteDataSource.clearFavorites(type);
    }

//    @Override
//    public Observable<Response<Object>> buy(String goodsId, int addressId, int number, String price, String address, int type) {
//        return mRemoteDataSource.buy(goodsId, addressId, number, price, address, type);
//    }

    @Override
    public Observable<Response<OrderCreate>> createOrder(String goods_id, int address_id, int num) {
        return mRemoteDataSource.createOrder(goods_id, address_id, num);
    }

    @Override
    public Observable<Response<Object>> payOrder(Long order_id, String pay_network, String pay_hash) {
        return mRemoteDataSource.payOrder(order_id, pay_network, pay_hash);
    }

    @Override
    public Observable<Response<OrderDetails>> orderDetails(String id) {
        return mRemoteDataSource.orderDetails(id);
    }

    @Override
    public Observable<Response<Object>> upGoodsStatus(String id, int status) {
        return mRemoteDataSource.upGoodsStatus(id, status);
    }

    @Override
    public Observable<Response<PageResponse<OrderScore>>> getGoodsScoreList(String goods_id, int page, int size) {
        return mRemoteDataSource.getGoodsScoreList(goods_id, page, size);
    }

    @Override
    public Observable<Response<Object>> addGoods(int type, String name, String goods_img, String label, String desc, float price, int total_stock, String notice) {
        return mRemoteDataSource.addGoods(type, name, goods_img, label, desc, price, total_stock, notice);
    }

    @Override
    public Observable<Response<Object>> updateGoods(String id, int type, String name, String goods_img, String label, String desc, float price, int total_stock, String notice) {
        return mRemoteDataSource.updateGoods(id, type, name, goods_img, label, desc, price, total_stock, notice);
    }

    @Override
    public Observable<Response<Object>> upGoodsPrice(String id, float price) {
        return mRemoteDataSource.upGoodsPrice(id, price);
    }

    @Override
    public Observable<Response<Object>> upGoodsStock(String id, int stock_type, int num) {
        return mRemoteDataSource.upGoodsStock(id, stock_type, num);
    }

    @Override
    public Observable<Response<Object>> delGoods(String id) {
        return mRemoteDataSource.delGoods(id);
    }

    @Override
    public Observable<Response<Object>> sendOrder(Long order_id, String send_id, String send_code) {
        return mRemoteDataSource.sendOrder(order_id, send_id, send_code);
    }

    @Override
    public Observable<Response<List<OrderCompany>>> logisticsList() {
        return mRemoteDataSource.logisticsList();
    }

    @Override
    public Observable<Response<PageResponse<ServiceOrder>>> kefuOrderList(int page, int size, int type, String keyword) {
        return mRemoteDataSource.kefuOrderList(page, size, type, keyword);
    }

    @Override
    public Observable<Response<Object>> confirmReceipt(Long order_id) {
        return mRemoteDataSource.confirmReceipt(order_id);
    }

    @Override
    public Observable<Response<Object>> orderRating(Long order_id, Integer score) {
        return mRemoteDataSource.orderRating(order_id, score);
    }

}
